package cn.laixueit.utils;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.Instant;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.util.Date;
import java.util.UUID;

public class Utils {

    public static int getYear(String birthday)  {
        try {
            Date date = new SimpleDateFormat("yyyy-mm-dd").parse(birthday);
            Instant instant = date.toInstant();
            ZoneId zoneId = ZoneId.systemDefault();
            LocalDateTime localDateTime = LocalDateTime.ofInstant(instant, zoneId);
            int year = localDateTime.toLocalDate().getYear();
            return year;
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return 0;
    }

    public static String getUUID(int len){
        return UUID.randomUUID().toString().replace("-","").substring(0,len);
    }

}
